package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Setmeal;
import com.itheima.reggie.entity.dto.SetmealDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetMealMapper {
    @Select("SELECT COUNT(*) FROM setmeal WHERE category_id=#{id}")
    int findCount(Long id);

    @Insert("insert into setmeal values(null,#{categoryId},#{name},#{price},#{status},#{code},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void save(SetmealDto setmealDto);

    List<Setmeal> findByName(@Param("name") String name);

    Long selectCount(@Param("ids") List<Long> ids);

    void deleteByIds(@Param("ids") List<Long> ids);

    void changeStatus(Integer status, List<Long> ids);

    void updateById(SetmealDto setmealDto);

    @Select("select * from setmeal where id = #{id}")
    Setmeal findById(Long setmealId);

    @Select("select * from setmeal where category_id=#{categoryId} and status=#{status}")
    List<Setmeal> list(@Param("categoryId") Long categoryId, @Param("status") Integer status);
}
